<script src="https://cdn.bootcss.com/socket.io/2.1.1/socket.io.js"></script>

<script type="text/javascript">

    var socket = io.connect('http://localhost:8082?userId=1', {
        'reconnection delay' : 2000,
        'force new connection' : true
    });

    socket.on('message', function(data) {
        // here is your handler on messages from server
        console.log(data)
    });

    socket.on('chatevent', function(data) {
        // here is your handler on chatevent from server
        console.log(data)
    });

    socket.on('connect', function() {
        // connection established, now we can send an objects


        // send json-object to server
        // '@class' property should be defined and should
        // equals to full class name.
        var obj = { '@class' : 'com.sample.SomeClass'
        }
        socket.json.send(obj);



        // send event-object to server
        // '@class' property is NOT necessary in this case
        var event = {

        }
        socket.emit('someevent', event);

    });

</script>
